<?php

namespace App\Http\Requests\Permission;

use App\Http\Requests\ApiRequest;
use Illuminate\Validation\Rule;

class AddPermissionRouterRequest extends ApiRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * 'store'：前端路由
     *
     * @return bool
     */
    public function authorize()
    {
        return self::checkPermission('store');
    }

    /**
     * @return array
     */
    public function rules()
    {
        return [
            'name' => 'required|string|unique:permissions,name',
            'type' => ['required', 'integer', Rule::in([0, 1])],
            'description' => 'required|string',
        ];
    }

    /**
     * 获取已定义验证规则的错误消息。
     *
     * @return array
     */
    public function messages()
    {
        return [
            'type.required'=>'请选择权限类型',
            'name.required'=>'请输入权限名称',
            'name.string'=>'权限名称必须为字符类型',
            'name.unique'=>'该权限路由已存在',
            'description.required' => '请填写权限描述',
            'description.string' => '权限描述必须为字符类型',
            'type.integer'=>'权限类型必须为整型',//权限类型 默认0-action类 1-menu类
        ];
    }
}
